
import { IStructInitInfo } from "../StructElement/type";
export const ToolBarInfos = new Map<string,IStructInitInfo>();
export default class ToolBar{
    private buttons:string[] = ["创建容器"];
    private container:HTMLElement;
    private toolBarContainer:HTMLElement;
    private toolBarButtons:Array<HTMLElement> = [];
    constructor(container:HTMLElement){
        this.container = container;
        this.toolBarContainer = document.createElement("div");
        this.initToolBar();
        this.createButtons();
    }
    public setStyle(styleStr:string){
        this.toolBarContainer.setAttribute("style", styleStr);
    }
    addClassName(className:string){
        this.toolBarContainer.setAttribute("class", className);
    }
    removeClassName(className:string){
        this.toolBarContainer.setAttribute("class", (this.toolBarContainer.getAttribute("class")||"").replace(className,""));
    }
    private initToolBar(){
        // this.toolBarContainer.setAttribute("style",`
        //     padding:12px;
        //     background:#ddd;
        // `);
        this.container.appendChild(this.toolBarContainer);
    }
    private createButtons(){
        this.buttons.forEach(()=>{
            const button = document.createElement("div");
            button.innerHTML = "创建新的可拖拽元素";
            button.id = "firstbutton";
            button.setAttribute("draggable","true");
            button.setAttribute("style",`
                cursor:pointer;
            `);
            button.addEventListener("dragstart",function(ev){
                const transfer:any = ev.dataTransfer;
                ToolBarInfos.set("id",{id:100})
                transfer.setData("Text","id");
            });
            this.toolBarContainer.appendChild(button);
            this.toolBarButtons.push(button);
        })
    }
}